//index.js
var util= require("../../utils/libs.js");
var api = require("../../utils/api.js");
var util= require("../../utils/libs.js")
var data= require("../../utils/date.js")
//获取应用实例
const app = getApp()

Page({
  data: {
    uid:1,
    id:null,
    toplist:{}
  },
  topicDraft(){
    let that = this
    util.request(api.topicDraft,{uid:that.data.uid},"GET")
    .then(function (res) {
      if(res.error_code === 0){
        console.log(res)
        let arr = res.data.topic
        arr.create_time = data.data(arr.create_time)
        that.setData({
          toplist:arr,
          id:arr.id
        })
      }
    })

  },
  add(){
    wx.navigateTo({
      url:"/pages/titlewriting/titlewriting"
    })
  },
  removeTitle(){
    let that = this
    util.request(api.topicDeleteTopicDraft,{id:that.data.id},"POST")
    .then(function (res) {
      if(res.error_code === 0){
        wx.showToast({
          title: '删除成功',
          icon: 'success',
          duration: 2000,
          success:function(){
            wx.navigateTo({
              url:"/pages/titlewriting/titlewriting"
            })
          }
        })
      }
    })
  },
  onLoad(){
   let that = this
   let uid = wx.getStorageSync("uid")
   that.setData({uid:uid})
   that.topicDraft()
  }
})
